//角色列表 0
//添加角色 1
//角色详情 2
//修改角色 3
//分配权限 4

define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";
	
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');

var history=require('component-history');

require('component-page');
	
var roleName,selectRoleId;

//var formIndex=0;//识别分页函数属于那个页面（0:终端列表,1:群组列表）

//var tips_index=0;



/**
 * 查询角色列表
 */
exports.init=function(m) {
	history.addHis(this,arguments);//增加历史
	window.$ddf_role = m;
	resetSearchParams();
		var htmlStr="";
	
    	htmlStr += '<div id="content-header">';
    	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="#" class="current">角色管理</a></div>';
    	//htmlStr += '<h1>角色管理</h1>';
    	htmlStr += '</div>    ';
    	htmlStr += '<div class="container-fluid">';
    	//htmlStr += '<hr/>';
    	htmlStr += '<div class="row-fluid">';
    	htmlStr += '<div class="span12">';
    	
    	htmlStr += '<div id="alert-tips0" ></div>';
    	
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title">';
    	htmlStr += '<span class="icon">';
    	htmlStr += '<i class="icon-search"></i>';
    	htmlStr += '</span>';
    	htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
    	htmlStr += '</div> ';
    	htmlStr += '<div class="widget-content nopadding">';
    	htmlStr += '<form class="form-horizontal">';
    	htmlStr += '<div class="row-fluid">';
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">角色名称：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="roleName"/>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="form-actions">';
    	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_role.searchRole()">搜索</button>';
    	htmlStr += ' <button class="btn btn-info" type="button" onclick="$ddf_role.resetSearchParams()">重置</button>';
    	htmlStr += ' <button class="btn btn-success" type="button" onclick="$ddf_role.openAddRole()">增加</button>';
    	htmlStr += '</div>';
    	htmlStr += '</form>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
    	htmlStr += '<h5>角色列表</h5>';
    	htmlStr += '</div>';
    	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
    	htmlStr += '<table class="table table-bordered data-table record">';
    	htmlStr += '<thead>';
    	htmlStr += '<tr>';
    	htmlStr += '<th>序号</th>';
    	htmlStr += '<th>角色编码</th>';
    	htmlStr += '<th>角色名称</th>';
    	htmlStr += '<th>操作</th>';
    	htmlStr += '</tr>'; 
    	htmlStr += '</thead>';
    	htmlStr += '<tbody id="roleList">';
    	
    	
    	
    	htmlStr += '</tbody>';
    	htmlStr += '</table>';
//    	htmlStr += '<div class=" ui-toolbar ui-widget-header " id="footPageDiv0">';
    	htmlStr += '<div id="footPageDiv0">';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	showDiv("content0");
    	
    	$("#content0").html(htmlStr);
    	
		
    	getQueryRole(1,10,roleName);
    	
}


/**
 * 查询Terminal列表
 * @param pageNumber
 * @param terminalId
 */
function getQueryRole(pageNumber,pageSize,roleName){
	
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize":pageSize,
			"roleName":roleName
	        };
	
	
	base.showLoading();
	

	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.getQueryRole,params));
		
		loadRoleListCallBack(data);
		
	}))().start();
	
}

/**
 * 加载角色列表回调函数
 */
function loadRoleListCallBack(data){
	if(data["code"]==1){
		
    	
    	var htmlStr="";
    	
    	
    	
    	for(var i=0;i<data["roleListData"].length;i++){
    		
    		
    		htmlStr += ' <tr>';
    		htmlStr += '<td>'+base.getSequence(data["pageNumber"],data["pageSize"],i+1)+'</td>';
    		htmlStr += '<td>'+data["roleListData"][i]["ROLE_ID"]+' </td>';
    		htmlStr += '<td>'+data["roleListData"][i]["ROLE_NAME"]+' </td>';
    		htmlStr += '<td>';
    		htmlStr += '<a href=javascript:$ddf_role.loadRoleDetail("'+data["roleListData"][i]["ROLE_ID"]+'")>修改</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
    		htmlStr += '<a href=javascript:$ddf_role.loadAssignAuthDetail("'+data["roleListData"][i]["ROLE_ID"]+'")>分配权限</a>';
    		htmlStr += '</td> ';
    		htmlStr += '</tr> ';
    		
    	}
    	$("#roleList").html(htmlStr);
    	
//		setPage(0,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_role");
    	 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
    		 
			 changePageCallback:function(pageSize,page){  
				 getQueryRole(page,pageSize,roleName);
	
			 },
			 changePageSizeCallBack:function(pageSize){
				 getQueryRole(1,pageSize,roleName);
			 } 
         }); 
    	
	}else{
		 
		 base.tips_error(data["message"])
		
	}

	base.cancelLoading();
}

/**
 * 重置参数
 */
function resetSearchParams(){
	
	
	roleName="";
	
	$("#roleName").val("");
	
}

/**
 * 搜索角色
 */
function searchRole(){
	
	roleName=$("#roleName").val();
	
	getQueryRole(1,10,roleName);
	
}

/**
 * 打开添加角色
 */
function openAddRole(){
	history.addHis(this,arguments);//增加历史
	var htmlStr="";
	 
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_role.showDiv("content0")>角色管理</a><a href="#" class="current">新增角色</a></div>';
	//htmlStr += '<h1>新增角色</h1>';
	htmlStr += '</div> ';
	htmlStr += '<div class="container-fluid">';
	//htmlStr += '<hr/>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	
	htmlStr += '<div id="alert-tips1" ></div>';
    
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>新增角色</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	   ';
	
	htmlStr += '<div class="control-group" id="control-group-roleName">';
	htmlStr += '<label class="control-label">角色名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-roleName" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
		
	
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_role.saveRole()" >保存</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_role.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
	showDiv("content1")
	
	$("#content1").html(htmlStr);
	
	
	$("#input-roleName").change(function() {

		var roleName=$("#input-roleName").val();

		if(isNull(roleName)){
			base.addErrorMessage("control-group-roleName","input-roleName","角色名称非法");
		}else{
			base.clearErrorMessage("control-group-roleName");
		}

	});
	
}


/**
 * 保存角色
 */
function saveRole(){
	
	
	var roleName=$("#input-roleName").val();
	
	
	if(isNull(roleName)){
		base.addErrorMessage("control-group-roleName","input-roleName","角色名称非法");
		return;
	}
	
	var params={
			"role.roleName":roleName
	        };
	
	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.addRole,params));
		
		saveRoleCallBack(data);
		
	}))().start();
	
	
}

/**
 * 保存角色_回调函数
 * @param data
 */
function saveRoleCallBack(data){
	
	
	if(data["code"]==1){
		
		showDiv("content0");
		base.tips("增加角色成功");
		getQueryRole(1,10,roleName);
		
	}else{
		
		base.tips_error(data["message"])
	}
	base.cancelLoading();
	
}


/**
 *查看角色详细信息
 * @param roleId
 */
function loadRoleDetail(roleId){
	history.addHis(this,arguments);//增加历史
	selectRoleId=roleId;
	
	$("#content1").html(""); //清空添加页面，防止页面标签ID冲突
	
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_role.showDiv("content0");>角色管理</a><a href="#" class="current">详情</a></div>';
	//htmlStr += '<h1>角色详情</h1>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	//htmlStr += '<hr/>';

	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	
	htmlStr += '<div id="alert-tips2" ></div>';
    
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>角色信息</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	   ';
	
	
	htmlStr += '<div class="control-group" id="control-group-roleName">';
	htmlStr += '<label class="control-label">角色名称：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-roleName" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_role.updateRole()" >保存</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_role.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	
	
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
	
	showDiv("content2");
	
	$("#content2").html(htmlStr);
	
	var params={
				
				"role.roleId":roleId
		        };
	
	 base.showLoading();	


	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.getRoleDetails,params));
		
		loadRoleDetailCallBack(data);
		
	}))().start();
	
	
	}

	/**
	 * 角色详情回调函数
	 */
	function loadRoleDetailCallBack(data){
		
		if(data["code"]==1){
			$("#input-roleName").val(data["ROLE_NAME"]);
			
		}else{
			base.tips_error(data["message"])
			
		}
		
		base.cancelLoading();
		
		
	}

	/**
	 * 更新角色信息
	 */
	function updateRole(){
		
		var inputRoleName=$("#input-roleName").val();
		
		if(isNull(inputRoleName)){
			base.addErrorMessage("control-group-roleName","input-roleName","角色名称非法");
			return;
		}
		
		var params={
				"role.roleId" :selectRoleId,
				"role.roleName":inputRoleName,
		        };
		
		
		base.showLoading();

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.updateRoleDetails,params));
			
			updateRoleCallBack(data);
			
		}))().start();
		
		
	}

	/**
	 * 更新角色_回调函数
	 * @param data
	 */
	function updateRoleCallBack(data){
		
		if(data["code"]==1){
			showDiv("content0");
			base.tips("编辑角色成功");
			getQueryRole(1,10,roleName);
		}else{
			base.tips_error(data["message"])

		}
		base.cancelLoading();
		
	}
	

	
/**
 * 查询角色权限详情
 * @param _selectRoleId
 */	
function loadAssignAuthDetail(_selectRoleId){
	history.addHis(this,arguments);//增加历史
	selectRoleId=_selectRoleId;
	var params={
			"roleId" :selectRoleId
	        };
	getQueryRoleAuthDetailsCallBack();
}

/**
 * 查询角色权限详情_回调函数
 */	
function getQueryRoleAuthDetailsCallBack(){
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_role.showDiv("content0")>角色管理</a><a href="#" class="current">分配权限</a></div>';
	//htmlStr += '<h1>分配权限</h1>';
	htmlStr += '</div>    ';
	htmlStr += '<div class="container-fluid">';
	//htmlStr += '<hr/>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	
	
	htmlStr += '<div id="alert-tips3" ></div>';
	
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon">';
	htmlStr += '<i class="icon-pencil"></i>';
	htmlStr += '</span>';
	htmlStr += '<h5>添加权限</h5>';
	htmlStr += '</div> ';  
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="div-btn">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_role.saveRoleAuth()" >确认分配</button>  ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_role.showDiv("content0");>返回</button>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>	';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon">';
	htmlStr += '<i class="icon-list"></i>';
	htmlStr += '</span>';
	htmlStr += '<h5>分配权限</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal" id="authListDiv">';
	
	
	htmlStr += '</div>';
	
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	
	showDiv("content3");
	
	$("#content3").html(htmlStr);
	
	base.setRadioStyle();//设置复选框样式
	
	changeAuthListDiv();
	
}



/**
 * 获取权限列表DIV内容
 */
var roleAuthIdArray;

function changeAuthListDiv(){
	
	roleAuthIdArray=new Array();
	
		
	var params={
		"roleId" :selectRoleId
	};

	
	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.getQuerySystemAuthForm,params));
		
		getQuerySystemAuthFormCallBack(data);
		
	}))().start();
	
	
	
}

/**
 * 权限列表_回调函数
 * @param data
 */
function getQuerySystemAuthFormCallBack(data){
	
	var htmlStr="";
	
	//var childStr="";
	
	for(var i=0;i<data["authRoleListData"].length;i++){
		htmlStr += '<div class="control-group">';
		htmlStr += '<dl class="permission">';
		//判断角色是否存在该父权限
		if(data["authRoleListData"][i]["ROLE_AUTH_ID"]!=""){
			htmlStr += '<dt><label><input type="checkbox" id="permission'+i+'" value="'+data["authRoleListData"][i]["AUTH_ID"]+'" onclick=$ddf_role.checkboxAll("permission'+i+'") name="authName" checked />'+data["authRoleListData"][i]["AUTH_NAME"]+'</label></dt>';
		
			roleAuthIdArray.push(data["authRoleListData"][i]["ROLE_AUTH_ID"]);
		}else{
			htmlStr += '<dt><label><input type="checkbox" id="permission'+i+'" value="'+data["authRoleListData"][i]["AUTH_ID"]+'" onclick=$ddf_role.checkboxAll("permission'+i+'") name="authName" />'+data["authRoleListData"][i]["AUTH_NAME"]+'</label></dt>';
		}
		
		for(var j=0;j<data["authRoleListData"][i]["CHILD_MUNU"].length;j++){
			
			var functionStr="";
			for(var k=0;k<data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"].length;k++){
				
				//判断角色是否存在该子权限
				if(data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["ROLE_AUTH_ID"]!=""){
					
					//functionStr += '<dd><label><input type="checkbox" name="authName" id="permission_dd_f'+i+j+k+'" onclick=$ddf_role.checkboxFunction("permission_dd_f'+i+j+k+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_ID"]+'" checked />'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_NAME"]+'</label></dd>';
					functionStr += '<label><input type="checkbox" name="authName" id="permission_dd_f'+i+j+k+'" onclick=$ddf_role.checkboxFunction("permission_dd_f'+i+j+k+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_ID"]+'" checked/>'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_NAME"]+'</label>';
					roleAuthIdArray.push(data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["ROLE_AUTH_ID"]);

				}else{
					
					//functionStr += '<dd><label><input type="checkbox" name="authName" id="permission_dd_f'+i+j+k+'" onclick=$ddf_role.checkboxFunction("permission_dd_f'+i+j+k+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_ID"]+'" />'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_NAME"]+'</label></dd>';
					functionStr += '<label><input type="checkbox" name="authName" id="permission_dd_f'+i+j+k+'" onclick=$ddf_role.checkboxFunction("permission_dd_f'+i+j+k+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_ID"]+'" />'+data["authRoleListData"][i]["CHILD_MUNU"][j]["FUNCTION_MUNU"][k]["AUTH_NAME"]+'</label>';

				}
			}
			
			//判断角色是否存在该子权限
			if(data["authRoleListData"][i]["CHILD_MUNU"][j]["ROLE_AUTH_ID"]!=""){
				
				htmlStr += '<dd><label><input type="checkbox" name="authName" id="permission_dd'+i+j+'" onclick=$ddf_role.checkboxSingle("permission_dd'+i+j+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["AUTH_ID"]+'" checked />'+data["authRoleListData"][i]["CHILD_MUNU"][j]["AUTH_NAME"]+'</label><div class="secondary">'+functionStr+'</div></dd>';
				
				roleAuthIdArray.push(data["authRoleListData"][i]["CHILD_MUNU"][j]["ROLE_AUTH_ID"]);
			}else{
				
				htmlStr += '<dd><label><input type="checkbox" name="authName" id="permission_dd'+i+j+'" onclick=$ddf_role.checkboxSingle("permission_dd'+i+j+'") value="'+data["authRoleListData"][i]["CHILD_MUNU"][j]["AUTH_ID"]+'" />'+data["authRoleListData"][i]["CHILD_MUNU"][j]["AUTH_NAME"]+'</label><div class="secondary">'+functionStr+'</div></dd>';

			}
			
		}
		
		htmlStr += '</dl>';
		
		htmlStr += '</div>';
		
	}
	
	$("#authListDiv").html(htmlStr);
	
	$('input[type=checkbox],input[type=radio],input[type=file]').uniform();
	
	base.cancelLoading();
}

//复选框全选
function checkboxAll(id){
	
	var dt_checkbox=$("#"+id);	
		
	if (dt_checkbox.attr("checked")=="checked") {
			
			dt_checkbox.parents(".permission").find("dd input:checkbox").parents("span").addClass('checked');
			dt_checkbox.parents(".permission").find("dd input:checkbox").attr("checked","checked")
			
	} else {
		
			dt_checkbox.parents(".permission").find("dd input:checkbox").parents("span").removeClass('checked');
			dt_checkbox.parents(".permission").find("dd input:checkbox").attr("checked",false)
	}	
	
}

//选择某一项
function checkboxSingle(id){
	
	var obj=$("#"+id);	
	
	//obj.parents(".permission").find("dt input:checkbox").parents("span").addClass('checked');
	
	//obj.parents(".permission").find("dt input:checkbox").attr("checked","checked")
	
	if (obj.parents("span").attr("class")=="checked") {
		
		obj.parents("span").removeClass('checked');
		obj.attr("checked",false)

	} else {
		
		obj.parents("span").addClass('checked');
		obj.attr("checked","checked")
	}	
	
	
	
}

//选择权限功能(第三级权限)
function checkboxFunction(id){
	
	var obj=$("#"+id);	
	
	obj.parents(".permission").find("dt input:checkbox").parents("span").addClass('checked');
	
	obj.parents(".permission").find("dt input:checkbox").attr("checked","checked")
	
	if (obj.parents("span").attr("class")=="checked") {
		
		obj.parents("span").removeClass('checked');
		obj.attr("checked",false)

	} else {
		
		obj.parents("span").addClass('checked');
		obj.attr("checked","checked")
	}		
}

/**
 * 分配权限
 */
function saveRoleAuth(){
	
	var params={
			
			"role.roleId":selectRoleId
				
		};
	var num = 0;
	var chk = document.getElementsByName("authName");
	for (var i = 0; i < chk.length; i++) {
		if (chk[i].checked == true) {
			
			params["checkBoxAuth["+num+"]"]=chk[i].value;
			num++;  
		}
	}
	
	var index = 0;
	for(var i=0;i<roleAuthIdArray.length;i++){
		
		if (!isNull(roleAuthIdArray[i])) {
			
			params["roleAuthId["+index+"]"]=roleAuthIdArray[i];
			index++;
		}
		
	}
	
	
	
	if (num == 0) {
		base.tips_error("请至少选择一个权限");

	} else {
		
		base.showLoading();
		
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.role.assignAuth,params));
			
			saveRoleAuthCallBack(data);
			
		}))().start();
		
		
	}
	
	
}

/**
 * 分配权限_回调函数
 */
function saveRoleAuthCallBack(data){
	
	base.cancelLoading();
	if(data["code"]==1){
		changeAuthListDiv();
		base.tips(data["message"]);

	}else{
		base.tips_error(data["message"])
	}
		
}




/**
 * 显示DIV
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	

	
}


//暴露方法
exports.getQueryRole=getQueryRole;
exports.resetSearchParams=resetSearchParams;
exports.searchRole=searchRole;
exports.openAddRole=openAddRole;
exports.saveRole=saveRole;
exports.loadRoleDetail=loadRoleDetail;
exports.updateRole=updateRole;
exports.loadAssignAuthDetail=loadAssignAuthDetail;
exports.changeAuthListDiv=changeAuthListDiv;
exports.checkboxAll=checkboxAll;
exports.checkboxSingle=checkboxSingle;
exports.saveRoleAuth=saveRoleAuth;

exports.showDiv=showDiv;

});